FROM golang:1.22-alpine AS builder

ENV GO111MODULE=on \
    GOPROXY=https://goproxy.cn,direct \
    CGO_ENABLED=0 \
    GOOS=linux \
    GOARCH=amd64

WORKDIR /build

COPY . .

RUN go mod tidy
RUN go build -o rbac .


FROM ubuntu:latest

WORKDIR /app

COPY ./wait-for.sh .
COPY ./conf /app/conf
COPY ./static /app/static
COPY --from=builder /build/rbac .

RUN set -eux; \
    apt-get update; \
    apt-get install -y \
        --no-install-recommends \
        netcat; \
        chmod 755 wait-for.sh;

# ENTRYPOINT ["/app/rbac"]
